/**
 * 版权所有：厦门市巨龙信息科技有限公司
 * Copyright 2023 Xiamen Dragoninfo Eng. Co. Ltd.
 * All right reserved.
 */
package com.github.alfred.database.adapter;


import cn.hutool.core.util.StrUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * 类说明
 * 数据库适配处理
 *
 * @author chengh
 * @date 2023/9/15 13:30
 */
public class DatabaseAdapterHandler {

    private DatabaseAdapterHandler() {

    }

    private static final Map<String, IDatabaseAdapterProvider> EVENT_SERVICE_MAP = new HashMap<String, IDatabaseAdapterProvider>();

    /**
     * 默认值
     */
    private static final IDatabaseAdapterProvider DEFAULT_HANDLER = null;

    public static IDatabaseAdapterProvider getHandler(String type) {
        //此处判空，没有可以抛异常
        if (StrUtil.isEmpty(type) || !EVENT_SERVICE_MAP.containsKey(type)) {
            return DEFAULT_HANDLER;
        }
        return EVENT_SERVICE_MAP.get(type);
    }


    /**
     * 策略注册方法
     *
     * @param type
     * @param databaseAdapterProvider {@link  IDatabaseAdapterProvider}
     */
    public static void registerService(String type, IDatabaseAdapterProvider databaseAdapterProvider) {
        EVENT_SERVICE_MAP.put(type, databaseAdapterProvider);
    }
}
